package com.ymatou.iapi.godmch.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.GetMarkupConfigBean;
import com.ymatou.iapi.godmch.parameter.SetMarkupConfigBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.GetMarkupConfigCall;
import com.ymatou.iapi.godmch.service.SetMarkupConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

/**
 * 查询自动加价规则Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetMarkupConfig {
	private static GetMarkupConfigBean getmarkupconfigBean;
	private static GetMarkupConfigCall getmarkupconfigCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询自动加价规则Test");
	}

	@Before
	public void caseUp() {
		getmarkupconfigBean = new GetMarkupConfigBean();
		getmarkupconfigCall = new GetMarkupConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getmarkupconfigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetMarkupConfig_001() {
		Logger.start(true, "查询自动加价规格，成功");
		try {
			// 创建渠道商
			CreateCodeBean createAllMsgSellerMch = GodmchManageCallService.CreateAllMsgSellerMch();
			// 创建渠道商邀请码
			CreateCodeCall createCodeCall2 = GodmchManageCallService.createCodeCall(createAllMsgSellerMch);
			// 创建代理商
			Integer agentUserId = GodmchManageCallService.CreateSellerMch(
					createCodeCall2.getJsonObject().getAsJsonObject("result").get("code").getAsString());
			int rootUserId = createAllMsgSellerMch.getMchId();

			SetMarkupConfigBean bean = GodmchManageCallService.initSetMarketupBean(agentUserId,
					Arrays.asList(rootUserId));
			SetMarkupConfigCall call = GodmchManageCallService.SetMarketupBeanCall(bean);
			getmarkupconfigBean.setAgentId(agentUserId);
			getmarkupconfigBean.setSupplierIdList(Arrays.asList(rootUserId));
			getmarkupconfigCall.setData(getmarkupconfigBean);
			getmarkupconfigCall.callService();
			Logger.verifyEquals("200", getmarkupconfigCall.getString("status"), "验证code");
			JsonObject result = getmarkupconfigCall.getJsonObject().getAsJsonObject("result");
			Logger.verifyEquals(result.get("agentId").getAsInt(), agentUserId, "验证agentId");
			JsonObject list = result.getAsJsonArray("list").get(0).getAsJsonObject();
			Logger.verifyEquals(list.get("supplierId").getAsInt(), rootUserId, "验证supplierId");
			Logger.verifyEquals(list.get("markupType").getAsInt(), 1, "验证markupType");
			Logger.verifyEquals(list.get("percentage").getAsInt(), 33, "验证percentage");
			Logger.verifyEquals(list.get("decimalType").getAsInt(), 1, "验证decimalType");
			Logger.verifyEquals(list.get("onSaleType").getAsInt(), 1, "验证onSaleType");
			Logger.verifyEquals(list.get("refreshProduct").getAsBoolean(), true, "验证refreshProduct");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetMarkupConfig_002() {
		Logger.start(true, "查询自动加价规格，代理商id与供货商id关系不存在，成功");
		try {
			getmarkupconfigBean.setAgentId(1111);
			getmarkupconfigBean.setSupplierIdList(Arrays.asList(22222));
			getmarkupconfigCall.setData(getmarkupconfigBean);
			getmarkupconfigCall.callService();
			Logger.verifyEquals("200", getmarkupconfigCall.getString("status"), "验证code");
			String result = getmarkupconfigCall.getJsonObject().getAsJsonObject("result").toString();
			Logger.verifyEquals("{}", result, "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}